let transfer = str => {
  return str.split(' ').reverse().map(item => {
    let arr = item.split('');
    for(let i = 0;i < arr.length;i ++){
      if(arr[i].charCodeAt(0) >= 65 && arr[i].charCodeAt(0) <=90){
        arr[i] = arr[i].toLowerCase();
      }else if(arr[i].charCodeAt(0) >= 97 && arr[i].charCodeAt(0) <= 122){
        arr[i] = arr[i].toUpperCase();
      }
    }
    return arr.join('');
  }).join(' ')
}

let str = 'I am a student'
console.log(transfer(str))
